﻿@model CaptchaMvc.Models.DefaultBuildInfoModel
@{
    var title = ViewData.Get<string>("Title", string.Empty);
    var errorMessage = ViewData.Get<string>("ErrorMessage", string.Empty);
}

<div class="form-group">
    @if (!string.IsNullOrEmpty(title))
    {
        <label>@title</label>
    }
    <div class="row">
        <div class="col-xs-6">
            @if ((bool)ViewData["IsRequired"])
            {
                @Html.TextBox(Model.InputElementId, null, new Dictionary<string, object>
                                                  {
                                                      {"data-val", "true"},
                                                      {"data-val-required", ViewData["RequiredMessage"]},
                                                      {"class", "form-control"},
                                                      {"placeholder" , "请输入验证码" }

                                                  })
            }
            else
            {
                @Html.TextBox(Model.InputElementId, null, new Dictionary<string, object>
                                                  {
                                                      {"class", "form-control"},
                                                      { "placeholder" , "请输入验证码" }
                                                  })
            }
            @Html.ValidationMessage(Model.InputElementId)
        </div>
        <div class="col-xs-6">
            @{
                string id = Guid.NewGuid().ToString("N");
                string functionName = string.Format("______{0}________()", Guid.NewGuid().ToString("N"));
                <script type="text/javascript">
                    $(function () {
                        $('#@id').show();
                    });
                    function @functionName {
                            $('#@id').hide();
                        $.post("@Model.RefreshUrl", { @Model.TokenParameterName: $('#@Model.TokenElementId').val() },
                            function () {
                                $('#@id').show();
                            });
                        return false;
                    }
                </script>
                <img id="@Model.ImageElementId" src="@Model.ImageUrl" onclick="@functionName" />
                <input id="onclickid" type="hidden" value="@id" />
                @Html.Hidden(Model.TokenElementId, Model.TokenValue)
                <a name="captchaclick" href="javascript:;" id="@id" onclick="@functionName" style="display: none;">@ViewData["InputText"]</a>
            }
        </div>
    </div>
    <span id="codemessage" style="color:red">@errorMessage</span>
</div>
<script>
    $("#CaptchaInputText").blur(function myfunction() {
        if ($(this).val().length > 0) {
            $("#codemessage").hide();
        } else {
            $("#codemessage").show();
        }

    });
</script>